package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.system.mapper.FmFcMstrMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FmFcMstr;
import com.ruoyi.system.service.IFmFcMstrService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 图文档类别信息Controller
 * 
 * @author ruoyi
 * @date 2021-10-17
 */
@RestController
@RequestMapping("/system/mstr")
public class FmFcMstrController extends BaseController
{
    @Autowired
    private IFmFcMstrService fmFcMstrService;

    /**
     * 查询图文档类别信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:mstr:list')")
    @GetMapping("/list")
    public AjaxResult list(FmFcMstr fmFcMstr)
    {
        List<FmFcMstr> list = fmFcMstrService.selectFmFcMstrList(fmFcMstr);
        return AjaxResult.success(list);
    }

    /**
     * 导出图文档类别信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:mstr:export')")
    @Log(title = "图文档类别信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FmFcMstr fmFcMstr)
    {
        List<FmFcMstr> list = fmFcMstrService.selectFmFcMstrList(fmFcMstr);
        ExcelUtil<FmFcMstr> util = new ExcelUtil<FmFcMstr>(FmFcMstr.class);
        return util.exportExcel(list, "图文档类别信息数据");
    }

    /**
     * 获取图文档类别信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:mstr:query')")
    @GetMapping(value = "/{fcId}")
    public AjaxResult getInfo(@PathVariable("fcId") Long fcId)
    {
        return AjaxResult.success(fmFcMstrService.selectFmFcMstrByFcId(fcId));
    }

    /**
     * 新增图文档类别信息
     */
    @PreAuthorize("@ss.hasPermi('system:mstr:add')")
    @Log(title = "图文档类别信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmFcMstr fmFcMstr)
    {
        if (UserConstants.NOT_UNIQUE.equals(fmFcMstrService.checkfcNameUnique(fmFcMstr)))
        {
            return AjaxResult.error("新增部门'" + fmFcMstr.getFcName() + "'失败，部门名称已存在");
        }
        fmFcMstr.setCreateBy(getUsername());
        return toAjax(fmFcMstrService.insertFmFcMstr(fmFcMstr));
    }

    /**
     * 修改图文档类别信息
     */
    @PreAuthorize("@ss.hasPermi('system:mstr:edit')")
    @Log(title = "图文档类别信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmFcMstr fmFcMstr)
    {
        fmFcMstr.setUpdateBy(getUsername());
        return toAjax(fmFcMstrService.updateFmFcMstr(fmFcMstr));
    }

    /**
     * 删除图文档类别信息
     */
    @PreAuthorize("@ss.hasPermi('system:mstr:remove')")
    @Log(title = "图文档类别信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fcIds}")
    public AjaxResult remove(@PathVariable Long[] fcIds)
    {
        return toAjax(fmFcMstrService.deleteFmFcMstrByFcIds(fcIds));
    }
}
